package cate.game.role.history;

import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

@NoteClass(value = "主角历史记录项")
public class HistoryItem{

    @NoteField(value = "历史记录的联合主键")
    public HistoryKey key;

    @NoteField(value = "当前值")
    public long cur;

    @NoteField(value = "最小值")
    public long min;

    @NoteField(value = "最大值")
    public long max;

    @NoteField(value = "最近一次的记录更新时间")
    public long updateTime;

    public HistoryItem() {}

    public HistoryItem(int event, int tid, long value) {
        this.key = new HistoryKey(event, tid);
        this.cur = value;
        this.max = value;
        this.min = value;
    }

    /** 记录值 */
    public void setValue(long value, boolean add) {
        cur = add ? cur + value : value;
        if (cur < min) {
            min = cur;
        }
        if (cur > max) {
            max = cur;
        }
        updateTime = System.currentTimeMillis();
    }

    @Override
    public String toString() {
        return "HistoryItem{" +
                "key=" + key +
                ", cur=" + cur +
                ", min=" + min +
                ", max=" + max +
                ", updateTime=" + updateTime +
                '}';
    }
}
